import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-26
 * Time: 11:29
 */
public class Test03 {
    public static void main(String[] args) {
        //第一种构造方法
        ArrayList<Integer> list1 = new ArrayList<>();
        list1.add(2);
        list1.add(1);
        list1.add(3);

        //for循环遍历输出
        for (int i = 0; i < list1.size(); i++) {
            System.out.print(list1.get(i) + " ");
        }
        System.out.println();
        //for each 循环输出
        for (Integer x : list1) {
            System.out.print(x + " ");
        }
        System.out.println();
        //迭代器
        Iterator<Integer> it = list1.listIterator();
        while( it.hasNext()) {
            System.out.print(it.next() +" ");
        }
    }
}
